import configparser
import os

import yaml


def get_project_path():
    cf = os.path.realpath(__file__) # read_file.py
    cd = os.path.dirname(cf) # /ApiAuto_Test/caw
    cd = os.path.dirname(cd) # futureloan
    return cd + "\\"


def read_ini(path, section, key):
    path = get_project_path() + path
    cp = configparser.ConfigParser()
    cp.read(path, encoding='utf-8')
    value = cp.get(section, key)
    return value


def read_yaml(path):
    path = get_project_path() + path
    # 打开文件，读文件内容
    with open(path, 'r', encoding='utf-8') as f:
        c = f.read()
    # yaml提供的方法，将文件内容解析成yaml格式的  pip install pyYAML
    return yaml.load(c, Loader=yaml.FullLoader)



# 测试代码，用完可以删除
if __name__ == '__main__':
    print(read_yaml("data/register.yaml"))
    a = read_ini(r"data\env.ini", "env", "db")
    print(a)

